// var CommonUrl = "http://10.0.0.135:9097";
// var videoUrl = "http://10.0.0.135/uploadTest/uploadVideo";
// var imgSourceUrl = "http://10.0.0.135";
// var ftpURL = "ftp://10.0.0.135:2121/";
// var CommonUrl = "http://172.16.10.82:9097";
// var videoUrl = "http://172.16.10.82/uploadTest/uploadVideo";
// var imgSourceUrl = "http://172.16.10.82";
// var ftpURL = "ftp://172.16.10.82:2121/";
var CommonUrl = "http://172.16.32.194:9097";
var videoUrl = "http://172.16.32.194/uploadTest/uploadVideo";
var imgSourceUrl = "http://172.16.32.194";
var ftpURL = "ftp://http://172.16.32.194:2121/";
// 第一个界面初始化日志获取groupId
function InitializeCommonNetWork() {
    $.ajax({
        url: CommonUrl + "/sysLog/addNewLogs",
        method: "post",
        dataType: "json",
        contentType: "application/json",
        headers: {
            Authorization: `Bearer ${token}`,
        },
        data: JSON.stringify({
            id: "",
            scene: scene,
            sceneLevel: sceneLevel,
            courseType: courseType,
            classSort: classSort, //题目编号
            classType: classType,
            moodType: moodType, //情绪类型
            remarks: remarks,
            userId: userid,
            operationName: operationName,
            timestamp: currentTimestamp,
            additionalInfo: additionalInfo,
            isDelete: "",
        }),
        success: function (data) {
            groupId = JSON.parse(JSON.stringify(data.data));
        },
        error: function (error) {
            alert(JSON.stringify(error));
        },
    });
}
// 其余界面传递日志数据
function CommonNetWork() {
    $.ajax({
        url: CommonUrl + "/sysLog/addNewLogs",
        method: "post",
        dataType: "json",
        contentType: "application/json",
        headers: {
            Authorization: `Bearer ${token}`,
        },
        data: JSON.stringify({
            id: "",
            scene: scene,
            sceneLevel: sceneLevel,
            courseType: courseType,
            classSort: classSort, //题目编号
            groupId: groupId,
            classType: classType,
            moodType: moodType, //情绪类型
            remarks: remarks,
            userId: userid,
            operationName: operationName,
            timestamp: currentTimestamp,
            additionalInfo: additionalInfo,
            isDelete: "",
            groupId: groupId,
        }),
        success: function (data) {
            // alert(JSON.stringify(data))
        },
        error: function (error) {
            // alert(JSON.stringify(error))
        },
    });
}
function AuditoryPlay(index) {
    if (index == "1") {
        document.getElementById("audioBodyInfoOne").play();
        document.getElementById("audioBodyInfoTwo").pause();
        document.getElementById("audioBodyInfoThree").pause();
    } else if (index == "2") {
        document.getElementById("audioBodyInfoOne").pause();
        document.getElementById("audioBodyInfoTwo").play();
        document.getElementById("audioBodyInfoThree").pause();
    } else if (index == "3") {
        document.getElementById("audioBodyInfoOne").pause();
        document.getElementById("audioBodyInfoTwo").pause();
        document.getElementById("audioBodyInfoThree").play();
    }
}
var clicked1 = "";
var clicked2 = "";
var clicked3 = "";
// 选项1和选项2 为选对
function AuditoryClickOneTwo(index) {
    if (index == "1") {
        document.getElementById("AudioAnswerBodyOne").src = "http://172.16.32.194/button/A1.png";
        clicked1 = "right";
        if (clicked1 == "right" && clicked2 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
        if (clicked1 == "right" && clicked3 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    } else if (index == "2") {
        clicked2 = "right";
        document.getElementById("AudioAnswerBodyTwo").src = "http://172.16.32.194/button/B1.png";
        if (clicked1 == "right" && clicked2 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
        if (clicked2 == "right" && clicked3 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    } else if (index == "3") {
        clicked3 = "false";
        document.getElementById("AudioAnswerBodyThree").src = "http://172.16.32.194/button/C1.png";
        if (clicked1 == "right" && clicked3 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
        if (clicked2 == "right" && clicked3 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    }
}
function ImgAudioClick() {
    const gifImage = document.getElementById("faceStyle");
    gifImage.src = `${gifImage.src}?nocache=${new Date().getTime()}`;
    history.go(0);
}
//选项1和选项3  为选对
function AuditoryClickOneThree(index) {
    if (index == "1") {
        document.getElementById("AudioAnswerBodyOne").src = "http://172.16.32.194/button/A1.png";
        clicked1 = "right";
        if (clicked1 == "right" && clicked3 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
        if (clicked1 == "right" && clicked2 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    } else if (index == "2") {
        clicked2 = "false";
        document.getElementById("AudioAnswerBodyTwo").src = "http://172.16.32.194/button/B1.png";
        if (clicked1 == "right" && clicked2 == "false") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
        if (clicked2 == "false" && clicked3 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    } else if (index == "3") {
        clicked3 = "right";
        document.getElementById("AudioAnswerBodyThree").src = "http://172.16.32.194/button/C1.png";
        if (clicked1 == "right" && clicked3 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
        if (clicked2 == "false" && clicked3 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    }
}
function AuditoryClickTwoThree(index) {
    if (index == "1") {
        document.getElementById("AudioAnswerBodyOne").src = "http://172.16.32.194/button/A1.png";
        clicked1 = "false";
        if (clicked1 == "false" && clicked3 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
        if (clicked1 == "false" && clicked2 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
    } else if (index == "2") {
        clicked2 = "right";
        document.getElementById("AudioAnswerBodyTwo").src = "http://172.16.32.194/button/B1.png";
        if (clicked1 == "false" && clicked2 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
        if (clicked2 == "right" && clicked3 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
    } else if (index == "3") {
        clicked3 = "right";
        document.getElementById("AudioAnswerBodyThree").src = "http://172.16.32.194/button/C1.png";
        if (clicked1 == "false" && clicked3 == "right") {
            document.getElementById("backdropMistake").style.display = "block";
            document.getElementById("audioBodyMistake").style.display = "none";
            document.getElementById("audioBodyMistake").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "error";
            CommonNetWork();
        }
        if (clicked2 == "right" && clicked3 == "right") {
            document.getElementById("backdrop_bgright").style.display = "block";
            document.getElementById("audioBodyRight").style.display = "none";
            document.getElementById("audioBodyRight").play();
            currentTimestamp = Date.now();
            operationName = "ing";
            additionalInfo = "right";
            CommonNetWork();
        }
    }
}
//允许开通权限
function reqPermission(one_per, callback) {
    var perms = new Array();
    if (one_per) {
        perms.push(one_per);
    } else {
        perms = ["microphone"];
    }
    api.requestPermission(
        {
            list: perms,
            code: 100001,
        },
        function (ret, err) {
            if (callback) {
                callback(ret);
                return;
            }
            var str = "请求结果：\n";
            str += "请求码: " + ret.code + "\n";
            str += '是否勾选"不再询问"按钮: ' + (ret.never ? "是" : "否") + "\n";
            str += "请求结果: \n";
            var list = ret.list;
            for (var i in list) {
                str += list[i].name + "=" + list[i].granted + "\n";
            }
            console.log(JSON.stringify(ret));
        }
    );
}

function hasPermissionObj(one_per) {
    var perms = new Array();
    if (one_per) {
        perms.push(one_per);
    } else {
        perms = ["microphone"];
    }
    var rets = api.hasPermission({
        list: perms,
    });
    if (!one_per) {
        return;
    }
    return rets;
}
